import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Graphics;

public class TestCanvas extends Canvas{
	private AppMIDlet midlet;
	private String s1, s2;
	private char[] c; 
	private boolean showed;
	public TestCanvas(AppMIDlet midlet){
		this.midlet = midlet;
		s1 = "";
		s2 = "";
		c = new char[1];
		showed = false;
		setFullScreenMode(true);
	}
	public void paint(Graphics g){
		g.setColor(0,0,0);
		g.fillRect(0,0,getWidth(),getHeight());
		g.setColor(255,255,255);
		g.fillRect(0,0,128,160);
		g.setColor(0,0,0);
		g.drawString("Ma ASCII:", 38,65,0);
		g.drawString("Ky tu tuong ung:", 20,95,0);
		g.drawString(s1, 50, 80,0);
		g.drawString(s2, 55, 110,0);
		g.drawString("Exit", 110,145,0);
		g.drawString("Show Form", 0, 145,0);	
	}
	protected void keyPressed(int keycode){
		if(keycode == -7)
			midlet.Exit();
		if(keycode == -6)
			midlet.showForm();
		if(keycode == -5){
			c[0] = (char)Integer.parseInt(s1);
			s2 = new String(c);			
			showed = true;	
		}
		if(keycode > 47){
			if(showed == true){
				s1 = "";
				showed = false;
			}
			s1 += getKeyName(keycode).toString();					
		}	
		repaint();	
	}
}